package com.avcdata.aoscustommade.model;

import android.content.Context;

import com.avcdata.aoscustommade.activity.SelectAgency_Activity;
import com.avcdata.aoscustommade.main.BaseCallBack;
import com.avcdata.aoscustommade.utils.AvcConstants;
import com.avcdata.aoscustommade.utils.http.AvcHttpUtils;
import com.avcdata.aoscustommade.utils.http.AvcJsonHttpResponseHandler;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

/**
 * 办事处选择的model
 * Created by zyh on 17/6/12.
 */

public class SelectAgencyModel {
    private final Context mContext;

    public SelectAgencyModel(Context context) {
        this.mContext = context;
    }

    /**
     * 下降数据
     * @param lastWeek
     * @param detailData
     * @param baseCallBack
     */
    public void loadDecline(String lastWeek, ArrayList<String> detailData, final BaseCallBack baseCallBack) {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("lastWeek", lastWeek);
            JSONArray array = new JSONArray();
            for (int i = 0, j = detailData.size(); i < j; i++) {
                array.put(detailData.get(i));
            }
            jsonObject.put("categories", array);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        AvcHttpUtils.post(AvcConstants.URLHeaderBase + "regionDown/city", jsonObject, true, new AvcJsonHttpResponseHandler(mContext){

            @Override
            public void onSuccess(JSONObject object) {
                super.onSuccess(object);
                baseCallBack.onSuccess(object);
            }

            @Override
            public void onFailure() {
                super.onFailure();
                baseCallBack.onFailure();
            }

            @Override
            public void onFailure(Throwable throwable) {
                super.onFailure(throwable);
                baseCallBack.onFailure(throwable);
            }
        });
    }
}
